import Loading from './Loading'

import Vue from 'vue'

function createLoading() {
  const LoadingConstructor = Vue.extend(Loading)
  const Profile = new LoadingConstructor({
    el: document.createElement('div')
  })
  document.body.appendChild(Profile.$el)

  return {
    open() {
      Profile.show = true
      hideScrollBar()
    },
    hide() {
      Profile.show = false
      showScrollBar()
    }
  }
}

function hideScrollBar() {
  document.body.style.height = '100%'
  document.body.style.overflow = 'hidden'
}

function showScrollBar() {
  document.body.style.height = '100%'
  document.body.style.overflow = 'auto'
}

export const LoadingObj = createLoading()

export default {
  install(Vue) {
    Vue.prototype.$Loading = createLoading()
  }
}
